#include <iostream>
#include <iomanip>
#include <cstring>
#include "utils.h"

/**
 * @brief 计算两点之间的距离
 */
static inline float getDistance(float x1, float y1, float x2, float y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main(int argc, char **argv)
{
	FILE *file;
	char buf[100];
	bool first = true;
	int cen_x, cen_y;
	int x, y;
	float dist;

	// 打开文件
	file = fopen("omnidirection.txt", "r");
	if (!file) {
		std::cerr << "can't open file omnidirection.txt" << std::endl;
		return 1;
	}

	// 读取文件
	while (fgets(buf, sizeof(buf), file)) {
		if (buf[0] == '#' || strlen(buf) == 1) { // 注释或空行
			continue;
		}
		if (first) {
			sscanf(buf, "%d %d", &cen_x, &cen_y);
			first = false;
		} else {
			sscanf(buf, "%d %d %f", &x, &y, &dist);
			std::cout << "pixel: "
				<< std::left << std::setw(10) << getDistance((float)cen_x, (float)cen_y, (float)x, (float)y)
				<< " origin: "
				<< std::left << std::setw(10) << dist
				<< " now: "
				<< std::left << std::setw(10) << pixToDistance(x, y, cen_x, cen_y) << std::endl;
		}
	}

	// 关闭文件
	fclose(file);

	std::cout << "Press CTRL+C to continue..." << std::endl;
	std::cin >> dist;

	return 0;
}
